package com.yytek.upgrade.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yytek.upgrade.mapper.UpgradeHistoryMapper;
import com.yytek.upgrade.domain.UpgradeHistory;
import com.yytek.upgrade.service.IUpgradeHistoryService;

/**
 * 升级记录Service业务层处理
 * 
 * @author yytek-iot
 * @date 2022-09-06
 */
@Service
public class UpgradeHistoryServiceImpl implements IUpgradeHistoryService 
{
    @Autowired
    private UpgradeHistoryMapper upgradeHistoryMapper;

    /**
     * 查询升级记录
     * 
     * @param id 升级记录主键
     * @return 升级记录
     */
    @Override
    public UpgradeHistory selectUpgradeHistoryById(Long id)
    {
        return upgradeHistoryMapper.selectUpgradeHistoryById(id);
    }

    /**
     * 查询升级记录列表
     * 
     * @param upgradeHistory 升级记录
     * @return 升级记录
     */
    @Override
    public List<UpgradeHistory> selectUpgradeHistoryList(UpgradeHistory upgradeHistory)
    {
        return upgradeHistoryMapper.selectUpgradeHistoryList(upgradeHistory);
    }

    /**
     * 新增升级记录
     * 
     * @param upgradeHistory 升级记录
     * @return 结果
     */
    @Override
    public int insertUpgradeHistory(UpgradeHistory upgradeHistory)
    {
        return upgradeHistoryMapper.insertUpgradeHistory(upgradeHistory);
    }

    /**
     * 修改升级记录
     * 
     * @param upgradeHistory 升级记录
     * @return 结果
     */
    @Override
    public int updateUpgradeHistory(UpgradeHistory upgradeHistory)
    {
        return upgradeHistoryMapper.updateUpgradeHistory(upgradeHistory);
    }

    /**
     * 批量删除升级记录
     * 
     * @param ids 需要删除的升级记录主键
     * @return 结果
     */
    @Override
    public int deleteUpgradeHistoryByIds(Long[] ids)
    {
        return upgradeHistoryMapper.deleteUpgradeHistoryByIds(ids);
    }

    /**
     * 删除升级记录信息
     * 
     * @param id 升级记录主键
     * @return 结果
     */
    @Override
    public int deleteUpgradeHistoryById(Long id)
    {
        return upgradeHistoryMapper.deleteUpgradeHistoryById(id);
    }

    /**
     * 更新设备升级记录状态
     * @param iotId 设备id
     * @param upgradeStrategyId 策略id
     * @param status 更新状态
     * @return
     */
    @Override
    public int changeStrategyHisStatus(String iotId, Long upgradeStrategyId, int status) {
        return upgradeHistoryMapper.changeHisStatusByIotIdAndStrategyId(iotId,upgradeStrategyId,status);
    }

    /**
     * 根据设备id和执行状态查询升级记录
     * @param iotId
     * @param status
     * @return
     */
    @Override
    public List<UpgradeHistory> selectUpgradeHisByIotId(String iotId, int status) {
        UpgradeHistory cx = new UpgradeHistory();
        cx.setDeviceId(iotId);
        cx.setExecStatus(status);
        return upgradeHistoryMapper.selectUpgradeHistoryList(cx);
    }
}
